use crate::co;
use crate::decl::*;
use crate::kernel::privs::*;
use crate::msg::*;
use crate::prelude::*;
use crate::user::privs::*;
pub struct AddFile {
pub text: WString,
}
unsafe impl MsgSend for AddFile {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
LB_ERRSPACE => Err(co::ERROR::NOT_ENOUGH_MEMORY),
idx => Ok(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::ADDFILE.into(),
wparam: 0,
lparam: self.text.as_ptr() as _,
}
}
}
pub struct AddString {
pub text: WString,
}
unsafe impl MsgSend for AddString {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
LB_ERRSPACE => Err(co::ERROR::NOT_ENOUGH_MEMORY),
idx => Ok(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::ADDSTRING.into(),
wparam: 0,
lparam: self.text.as_ptr() as _,
}
}
}
pub struct DeleteString {
pub index: u32,
}
unsafe impl MsgSend for DeleteString {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
count => Ok(count as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::DELETESTRING.into(),
wparam: self.index as _,
lparam: 0,
}
}
}
pub struct Dir {
pub attributes: co::DDL,
pub path: WString,
}
unsafe impl MsgSend for Dir {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
LB_ERRSPACE => Err(co::ERROR::NOT_ENOUGH_MEMORY),
idx => Ok(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::DIR.into(),
wparam: self.attributes.raw() as _,
lparam: self.path.as_ptr() as _,
}
}
}
pub struct FindString {
pub preceding_index: Option<u32>,
pub text: WString,
}
unsafe impl MsgSend for FindString {
type RetType = Option<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => None,
idx => Some(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::FINDSTRING.into(),
wparam: self.preceding_index.map_or(-1, |idx| idx as i32) as _,
lparam: self.text.as_ptr() as _,
}
}
}
pub struct FindStringExact {
pub preceding_index: Option<u32>,
pub text: WString,
}
unsafe impl MsgSend for FindStringExact {
type RetType = Option<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => None,
idx => Some(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::FINDSTRINGEXACT.into(),
wparam: self.preceding_index.map_or(-1, |idx| idx as i32) as _,
lparam: self.text.as_ptr() as _,
}
}
}
pub struct GetAnchorIndex {}
unsafe impl MsgSend for GetAnchorIndex {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETANCHORINDEX.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetCaretIndex {}
unsafe impl MsgSend for GetCaretIndex {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETCARETINDEX.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetCount {}
unsafe impl MsgSend for GetCount {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
count => Ok(count as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETCOUNT.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetCurSel {}
unsafe impl MsgSend for GetCurSel {
type RetType = Option<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => None,
idx => Some(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETCURSEL.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetHorizontalExtent {}
unsafe impl MsgSend for GetHorizontalExtent {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETHORIZONTALEXTENT.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetItemData {
pub index: u32,
}
unsafe impl MsgSend for GetItemData {
type RetType = SysResult<isize>;
fn convert_ret(&self, v: isize) -> Self::RetType {
const LB_ERR_ISIZE: isize = LB_ERR as _;
match v {
LB_ERR_ISIZE => Err(co::ERROR::BAD_ARGUMENTS),
data => Ok(data),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETITEMDATA.into(),
wparam: self.index as _,
lparam: 0,
}
}
}
pub struct GetItemHeight {
pub index: Option<u32>,
}
unsafe impl MsgSend for GetItemHeight {
type RetType = SysResult<u8>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
height => Ok(height as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETITEMHEIGHT.into(),
wparam: self.index.unwrap_or(0) as _,
lparam: 0,
}
}
}
pub struct GetItemRect<'a> {
pub index: u32,
pub rect: &'a mut RECT,
}
unsafe impl<'a> MsgSend for GetItemRect<'a> {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETITEMRECT.into(),
wparam: self.index as _,
lparam: self.rect as *mut _ as _,
}
}
}
pub struct GetListBoxInfo {}
unsafe impl MsgSend for GetListBoxInfo {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETLISTBOXINFO.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetLocale {}
unsafe impl MsgSend for GetLocale {
type RetType = LCID;
fn convert_ret(&self, v: isize) -> Self::RetType {
unsafe { LCID::from_raw(v as _) }
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETLOCALE.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetSel {
pub index: u32,
}
unsafe impl MsgSend for GetSel {
type RetType = SysResult<bool>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
status => Ok(status != 0),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETSEL.into(),
wparam: self.index as _,
lparam: 0,
}
}
}
pub struct GetSelCount {}
unsafe impl MsgSend for GetSelCount {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
count => Ok(count as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETSELCOUNT.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetSelItems<'a> {
pub buffer: &'a mut [u32],
}
unsafe impl<'a> MsgSend for GetSelItems<'a> {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
count => Ok(count as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETSELITEMS.into(),
wparam: self.buffer.len(),
lparam: self.buffer.as_mut_ptr() as _,
}
}
}
pub struct GetText<'a> {
pub index: u32,
pub text: &'a mut WString,
}
unsafe impl<'a> MsgSend for GetText<'a> {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
nchars => Ok(nchars as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETTEXT.into(),
wparam: self.index as _,
lparam: unsafe { self.text.as_mut_ptr() } as _,
}
}
}
pub struct GetTextLen {
pub index: u32,
}
unsafe impl MsgSend for GetTextLen {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
nchars => Ok(nchars as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETTEXTLEN.into(),
wparam: self.index as _,
lparam: 0,
}
}
}
pub struct GetTopIndex {}
unsafe impl MsgSend for GetTopIndex {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
idx => Ok(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::GETTOPINDEX.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct InitStorage {
pub num_items: u32,
pub memory_bytes: u32,
}
unsafe impl MsgSend for InitStorage {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERRSPACE => Err(co::ERROR::BAD_ARGUMENTS),
n_items => Ok(n_items as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::INITSTORAGE.into(),
wparam: self.num_items as _,
lparam: self.memory_bytes as _,
}
}
}
pub struct InsertString {
pub insertion_index: Option<u32>,
pub text: WString,
}
unsafe impl MsgSend for InsertString {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
LB_ERRSPACE => Err(co::ERROR::NOT_ENOUGH_MEMORY),
idx => Ok(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::INSERTSTRING.into(),
wparam: self.insertion_index.map_or(-1, |idx| idx as i32) as _,
lparam: self.text.as_ptr() as _,
}
}
}
pub struct ItemFromPoint {
pub coords: POINT,
}
unsafe impl MsgSend for ItemFromPoint {
type RetType = (i32, bool);
fn convert_ret(&self, v: isize) -> Self::RetType {
(LOWORD(v as _) as _, HIWORD(v as _) == 1)
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::ITEMFROMPOINT.into(),
wparam: 0,
lparam: u32::from(self.coords) as _,
}
}
}
pub_struct_msg_empty! { ResetContent: co::LB::RESETCONTENT.into();
}
pub struct SelectString {
pub index: Option<u32>,
pub prefix: WString,
}
unsafe impl MsgSend for SelectString {
type RetType = SysResult<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
LB_ERRSPACE => Err(co::ERROR::NOT_ENOUGH_MEMORY),
idx => Ok(idx as _),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SELECTSTRING.into(),
wparam: self.index.map_or(-1, |idx| idx as i32) as _,
lparam: self.prefix.as_ptr() as _,
}
}
}
pub struct SelItemRange {
pub select: bool,
pub first_item: u16,
pub last_item: u16,
}
unsafe impl MsgSend for SelItemRange {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SELITEMRANGE.into(),
wparam: self.select as _,
lparam: MAKEDWORD(self.first_item, self.last_item) as _,
}
}
}
pub struct SelItemRangeEx {
pub first_index: u32,
pub last_index: u32,
}
unsafe impl MsgSend for SelItemRangeEx {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SELITEMRANGEEX.into(),
wparam: self.first_index as _,
lparam: self.last_index as _,
}
}
}
pub struct SetAnchorIndex {
pub index: u32,
}
unsafe impl MsgSend for SetAnchorIndex {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETANCHORINDEX.into(),
wparam: self.index as _,
lparam: 0,
}
}
}
pub struct SetCaretIndex {
pub index: u32,
pub at_least_partially_visible: bool,
}
unsafe impl MsgSend for SetCaretIndex {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETCARETINDEX.into(),
wparam: self.index as _,
lparam: self.at_least_partially_visible as _,
}
}
}
pub struct SetColumnWidth {
pub width: u32,
}
unsafe impl MsgSend for SetColumnWidth {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETCOLUMNWIDTH.into(),
wparam: self.width as _,
lparam: 0,
}
}
}
pub struct SetCount {
pub new_count: u32,
}
unsafe impl MsgSend for SetCount {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
LB_ERRSPACE => Err(co::ERROR::NOT_ENOUGH_MEMORY),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETCOUNT.into(),
wparam: self.new_count as _,
lparam: 0,
}
}
}
pub struct SetCurSel {
pub index: Option<u32>,
}
unsafe impl MsgSend for SetCurSel {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
if let None = self.index {
Ok(())
} else {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETCURSEL.into(),
wparam: self.index.map_or(-1, |idx| idx as i32) as _,
lparam: 0,
}
}
}
pub struct SetHorizontalExtent {
pub width: u32,
}
unsafe impl MsgSend for SetHorizontalExtent {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETHORIZONTALEXTENT.into(),
wparam: self.width as _,
lparam: 0,
}
}
}
pub struct SetItemData {
pub index: u32,
pub data: isize,
}
unsafe impl MsgSend for SetItemData {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETITEMDATA.into(),
wparam: self.index as _,
lparam: self.data,
}
}
}
pub struct SetItemHeight {
pub index: Option<u32>,
pub height: u8,
}
unsafe impl MsgSend for SetItemHeight {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETITEMHEIGHT.into(),
wparam: self.index.unwrap_or(0) as _,
lparam: self.height as _,
}
}
}
pub struct SetLocale {
pub locale: LCID,
}
unsafe impl MsgSend for SetLocale {
type RetType = SysResult<LCID>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
lcid => Ok(unsafe { LCID::from_raw(lcid as _) }),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETLOCALE.into(),
wparam: u32::from(self.locale) as _,
lparam: 0,
}
}
}
pub struct SetSel {
pub select: bool,
pub index: Option<u32>,
}
unsafe impl MsgSend for SetSel {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETSEL.into(),
wparam: self.select as _,
lparam: self.index.map_or(-1, |idx| idx as i32) as _,
}
}
}
pub struct SetTabStops<'a> {
pub tab_stops: &'a [u32],
}
unsafe impl<'a> MsgSend for SetTabStops<'a> {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_badargs(v).map(|_| ())
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETTABSTOPS.into(),
wparam: self.tab_stops.len(),
lparam: vec_ptr(self.tab_stops) as _,
}
}
}
pub struct SetTopIndex {
pub index: u32,
}
unsafe impl MsgSend for SetTopIndex {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
match v as i32 {
LB_ERR => Err(co::ERROR::BAD_ARGUMENTS),
_ => Ok(()),
}
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::LB::SETTOPINDEX.into(),
wparam: self.index as _,
lparam: 0,
}
}
}